@import 'default';
@import "patch";

$table-prefix-cls: #{$style-prefix}-table;
$table-header-icon-color: #bfbfbf;
$table-header-sort-active-bg: darken($table-header-bg, 3%);
$table-header-filter-active-bg: darken($table-header-sort-active-bg, 5%);
$table-selection-column-width: 60px;

.#{$table-prefix-cls}-wrapper {
  @include clearfix;
}

.#{$table-prefix-cls} {
  @include reset-component;

  position: relative;
  clear: both;

  &-body {
    transition: opacity 0.3s;
  }

  &-empty &-body {
    // https://github.com/apes-design/apes-design/issues/11135
    overflow-x: auto !important;
    // https://github.com/apes-design/apes-design/issues/17175
    overflow-y: hidden !important;
  }

  // https://github.com/apes-design/apes-design/issues/17611
  table {
    width: 100%;
    text-align: left;
    border-radius: $table-border-radius-base $table-border-radius-base 0 0;
    border-collapse: separate;
    border-spacing: 0;
  }

  &-thead > tr > th {
    color: $table-header-color;
    font-weight: 500;
    text-align: left;
    background: $table-header-bg;
    border-bottom: $border-width-base $border-style-base $border-color-split;
    transition: background 0.3s ease;

    &[colspan] {
      text-align: center;
    }

    .#{$iconfont-css-prefix}-filter,
    .#{$table-prefix-cls}-filter-icon {
      position: absolute;
      top: 0;
      right: 0;
      width: 28px;
      height: 100%;
      color: $table-header-icon-color;
      font-size: $font-size-sm;
      text-align: center;
      cursor: pointer;
      transition: all 0.3s;

      > svg {
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: $font-size-sm / 2 + 1px;
        margin-left: $font-size-sm / 2;
      }
    }

    .#{$table-prefix-cls}-filter-selected.#{$iconfont-css-prefix}-filter {
      color: $primary-color;
    }

    .#{$table-prefix-cls}-column-sorter {
      display: table-cell;
      vertical-align: middle;

      .#{$table-prefix-cls}-column-sorter-inner {
        height: 1em;
        margin-top: 0.35em;
        margin-left: 0.57142857em;
        color: $table-header-icon-color;
        line-height: 1em;
        text-align: center;
        transition: all 0.3s;

        .#{$table-prefix-cls}-column-sorter-up,
        .#{$table-prefix-cls}-column-sorter-down {
          @include iconfont-size-under-12px(11px);

          display: block;
          height: 1em;
          line-height: 1em;
          transition: all 0.3s;
          &.on {
            color: $primary-color;
          }
        }

        &-full {
          margin-top: -0.15em;

          .#{$table-prefix-cls}-column-sorter-up,
          .#{$table-prefix-cls}-column-sorter-down {
            height: 0.5em;
            line-height: 0.5em;
          }

          .#{$table-prefix-cls}-column-sorter-down {
            margin-top: 0.125em;
          }
        }
      }
    }

    &.#{$table-prefix-cls}-column-has-actions {
      position: relative;
      background-clip: padding-box; // For Firefox background bug, https://github.com/apes-design/apes-design/issues/12628
      /* stylelint-disable-next-line */
      -webkit-background-clip: border-box; // For Chrome extra space: https://github.com/apes-design/apes-design/issues/14926

      &.#{$table-prefix-cls}-column-has-filters {
        // https://github.com/apes-design/apes-design/issues/12650
        padding-right: 30px !important;

        .#{$iconfont-css-prefix}-filter,
        .#{$table-prefix-cls}-filter-icon {
          &.#{$table-prefix-cls}-filter-open {
            color: $text-color-secondary;
            background: $table-header-filter-active-bg;
          }
        }
        // Very complicated styles logic but necessary
        &:hover {
          .#{$iconfont-css-prefix}-filter,
          .#{$table-prefix-cls}-filter-icon {
            &:hover {
              color: $text-color-secondary;
              background: $table-header-filter-active-bg;
            }
            &:active {
              color: $text-color;
            }
          }
        }
      }

      &.#{$table-prefix-cls}-column-has-sorters {
        cursor: pointer;
        &:hover {
          background: $table-header-sort-active-bg;
          .#{$iconfont-css-prefix}-filter,
          .#{$table-prefix-cls}-filter-icon {
            background: $table-header-sort-active-bg;
          }
        }
        &:active {
          .#{$table-prefix-cls}-column-sorter-up:not(.on),
          .#{$table-prefix-cls}-column-sorter-down:not(.on) {
            color: $text-color-secondary;
          }
        }
      }
    }

    .#{$table-prefix-cls}-header-column {
      display: inline-block;
      vertical-align: top;

      .#{$table-prefix-cls}-column-sorters {
        display: table;

        > .#{$table-prefix-cls}-column-title {
          display: table-cell;
          vertical-align: middle;
        }

        > *:not(.#{$table-prefix-cls}-column-sorter) {
          position: relative;
        }
        &::before {
          position: absolute;
          top: 0;
          right: 0;
          bottom: 0;
          left: 0;
          background: transparent;
          transition: all 0.3s;
          content: '';
        }
        &:hover::before {
          background: rgba(0, 0, 0, 0.04);
        }
      }
    }

    &.#{$table-prefix-cls}-column-has-sorters {
      user-select: none;
    }
  }

  &-thead > tr:first-child > th {
    &:first-child {
      border-top-left-radius: $table-border-radius-base;
    }

    &:last-child {
      border-top-right-radius: $table-border-radius-base;
    }
  }

  &-thead > tr:not(:last-child) > th {
    &[colspan] {
      border-bottom: 0;
    }
  }

  &-tbody > tr > td {
    border-bottom: $border-width-base $border-style-base $border-color-split;
    transition: all 0.3s, border 0s;
  }

  &-thead > tr,
  &-tbody > tr {
    transition: all 0.3s, height 0s;
    &.#{$table-prefix-cls}-row-hover,
    &:hover {
      &:not(.#{$table-prefix-cls}-expanded-row):not(.#{table-prefix-cls}-row-selected) > td {
        background: $table-row-hover-bg;
      }
    }
    &.#{$table-prefix-cls}-row-selected > td {
      &.#{$table-prefix-cls}-column-sort {
        background: $table-body-selected-sort-bg;
      }
    }
    &:hover {
      &.#{$table-prefix-cls}-row-selected > td {
        background: $table-selected-row-hover-bg;
        &.#{$table-prefix-cls}-column-sort {
          background: $table-body-selected-sort-bg;
        }
      }
    }
  }

  &-thead > tr:hover {
    background: none;
  }

  &-footer {
    position: relative;
    padding: $table-padding-vertical $table-padding-horizontal;
    color: $table-footer-color;
    background: $table-header-bg;
    border-top: $border-width-base $border-style-base $border-color-split;
    border-radius: 0 0 $table-border-radius-base $table-border-radius-base;
    &::before {
      position: absolute;
      top: -1px;
      left: 0;
      width: 100%;
      height: 1px;
      background: $table-header-bg;
      content: '';
    }
  }

  &.#{$table-prefix-cls}-bordered &-footer {
    border: $border-width-base $border-style-base $border-color-split;
  }

  &-title {
    position: relative;
    top: 1px;
    padding: $table-padding-vertical 0;
    border-radius: $table-border-radius-base $table-border-radius-base 0 0;
  }

  &.#{$table-prefix-cls}-bordered &-title {
    padding-right: $table-padding-horizontal;
    padding-left: $table-padding-horizontal;
    border: $border-width-base $border-style-base $border-color-split;
  }

  &-title + &-content {
    position: relative;
    border-radius: $table-border-radius-base $table-border-radius-base 0 0;

    .#{$table-prefix-cls}-bordered & {
      &,
      table,
      .#{$table-prefix-cls}-thead > tr:first-child > th {
        border-radius: 0;
      }
    }
  }

  // https://github.com/apes-design/apes-design/issues/4373
  &-without-column-header .#{$table-prefix-cls}-title + .#{$table-prefix-cls}-content,
  &-without-column-header table {
    border-radius: 0;
  }

  // https://github.com/apes-design/apes-design/issues/14834
  &-without-column-header.#{$table-prefix-cls}-bordered.#{$table-prefix-cls}-empty .#{$table-prefix-cls}-placeholder {
    border-top: 1px solid $border-color-split;
    border-radius: $border-radius-base;
  }

  &-tbody > tr.#{$table-prefix-cls}-row-selected td {
    color: $table-selected-row-color;
    background: $table-selected-row-bg;
  }

  &-thead > tr > th.#{$table-prefix-cls}-column-sort {
    background: $table-header-sort-bg;
  }

  &-tbody > tr > td.#{$table-prefix-cls}-column-sort {
    background: $table-body-sort-bg;
  }

  &-thead > tr > th,
  &-tbody > tr > td {
    padding: $table-padding-vertical $table-padding-horizontal;
  }

  &-expand-icon-th,
  &-row-expand-icon-cell {
    width: 50px;
    min-width: 50px;
    text-align: center;
  }

  &-header {
    overflow: hidden;
    background: $table-header-bg;
  }

  &-header table {
    border-radius: $table-border-radius-base $table-border-radius-base 0 0;
  }

  &-loading {
    position: relative;
    .#{$table-prefix-cls}-body {
      background: $component-background;
      opacity: 0.5;
    }
    .#{$table-prefix-cls}-spin-holder {
      position: absolute;
      top: 50%;
      left: 50%;
      height: 20px;
      margin-left: -30px;
      line-height: 20px;
    }
    .#{$table-prefix-cls}-with-pagination {
      margin-top: -20px;
    }
    .#{$table-prefix-cls}-without-pagination {
      margin-top: 10px;
    }
  }

  &-bordered {
    .#{$table-prefix-cls}-header > table,
    .#{$table-prefix-cls}-body > table,
    .#{$table-prefix-cls}-fixed-left table,
    .#{$table-prefix-cls}-fixed-right table {
      border: $border-width-base $border-style-base $border-color-split;
      border-right: 0;
      border-bottom: 0;
    }

    &.#{$table-prefix-cls}-empty {
      .#{$table-prefix-cls}-placeholder {
        border-right: $border-width-base $border-style-base $border-color-split;
        border-left: $border-width-base $border-style-base $border-color-split;
      }
    }

    &.#{$table-prefix-cls}-fixed-header {
      .#{$table-prefix-cls}-header > table {
        border-bottom: 0;
      }

      .#{$table-prefix-cls}-body > table {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
      }

      .#{$table-prefix-cls}-header + .#{$table-prefix-cls}-body > table,
      .#{$table-prefix-cls}-body-inner > table {
        border-top: 0;
      }
    }

    .#{$table-prefix-cls}-thead > tr:not(:last-child) > th {
      border-bottom: $border-width-base $border-style-base $border-color-split;
    }

    .#{$table-prefix-cls}-thead > tr > th,
    .#{$table-prefix-cls}-tbody > tr > td {
      border-right: $border-width-base $border-style-base $border-color-split;
    }
  }

  &-placeholder {
    position: relative;
    z-index: 1;
    margin-top: -1px;
    padding: $table-padding-vertical $table-padding-horizontal;
    color: $disabled-color;
    font-size: $font-size-base;
    text-align: center;
    background: $component-background;
    border-top: $border-width-base $border-style-base $border-color-split;
    border-bottom: $border-width-base $border-style-base $border-color-split;
    border-radius: 0 0 $border-radius-base $border-radius-base;
  }

  &-pagination.#{$style-prefix}-pagination {
    float: right;
    margin: 16px 0;
  }

  &-filter-dropdown {
    position: relative;
    min-width: 96px;
    margin-left: -8px;
    background: $component-background;
    border-radius: $border-radius-base;
    box-shadow: $box-shadow-base;

    .#{$style-prefix}-dropdown-menu {
      border: 0;
      border-radius: $border-radius-base $border-radius-base 0 0;
      box-shadow: none;

      // https://github.com/apes-design/apes-design/issues/4916
      &-without-submenu {
        max-height: 400px;
        overflow-x: hidden;
      }

      &-item > label + span {
        padding-right: 0;
      }

      &-sub {
        border-radius: $border-radius-base;
        box-shadow: $box-shadow-base;
      }

      .#{$style-prefix}-dropdown-submenu-contain-selected {
        .#{$style-prefix}-dropdown-menu-submenu-title::after {
          color: $primary-color;
          font-weight: bold;
          text-shadow: 0 0 2px $primary-2;
        }
      }
    }

    .#{$style-prefix}-dropdown-menu-item {
      overflow: hidden;
    }

    .#{$style-prefix}-checkbox-wrapper + span {
      padding-left: 8px;
    }

    > .#{$style-prefix}-dropdown-menu > .#{$style-prefix}-dropdown-menu-item:last-child,
    > .#{$style-prefix}-dropdown-menu
      > .#{$style-prefix}-dropdown-menu-submenu:last-child
      .#{$style-prefix}-dropdown-menu-submenu-title {
      border-radius: 0;
    }

    &-btns {
      padding: 7px 8px;
      overflow: hidden;
      border-top: $border-width-base $border-style-base $border-color-split;
    }

    &-link {
      color: $link-color;
      &:hover {
        color: $link-hover-color;
      }
      &:active {
        color: $link-active-color;
      }
      &.confirm {
        float: left;
      }
      &.clear {
        float: right;
      }
    }
  }

  &-selection {
    white-space: nowrap;

    &-select-all-custom {
      margin-right: 4px !important;
    }

    .#{$iconfont-css-prefix}-down {
      color: $table-header-icon-color;
      transition: all 0.3s;
    }

    &-menu {
      min-width: 96px;
      margin-top: 5px;
      margin-left: -30px;
      background: $component-background;
      border-radius: $border-radius-base;
      box-shadow: $box-shadow-base;

      .#{$style-prefix}-action-down {
        color: $table-header-icon-color;
      }
    }

    &-down {
      display: inline-block;
      padding: 0;
      line-height: 1;
      cursor: pointer;
      &:hover .#{$iconfont-css-prefix}-down {
        color: fade($black, 60%);
      }
    }
  }

  &-row {
    &-expand-icon {
      @include operation-unit;

      display: inline-block;
      width: 17px;
      height: 17px;
      color: inherit;
      line-height: 13px;
      text-align: center;
      background: $component-background;
      border: $border-width-base $border-style-base $border-color-split;
      border-radius: $border-radius-sm;
      outline: none;
      transition: all 0.3s;
      user-select: none;

      &:focus,
      &:hover,
      &:active {
        border-color: currentColor;
      }
    }

    &-expanded::after {
      content: '-';
    }

    &-collapsed::after {
      content: '+';
    }

    &-spaced {
      visibility: hidden;
      &::after {
        content: '.';
      }
    }
  }

  tr.#{$table-prefix-cls}-expanded-row {
    &,
    &:hover {
      background: $table-expanded-row-bg;
    }

    td > .#{$table-prefix-cls}-wrapper {
      margin: -$table-padding-vertical -$table-padding-horizontal -$table-padding-vertical - 1px;
    }
  }

  .#{$table-prefix-cls}-row-indent + .#{$table-prefix-cls}-row-expand-icon {
    margin-right: 8px;
  }

  &-scroll {
    overflow: auto;
    overflow-x: hidden;
    table {
      width: auto;
      min-width: 100%;

      // https://github.com/apes-design/apes-design/issues/14545
      .#{$table-prefix-cls}-fixed-columns-in-body {
        visibility: hidden;
      }
    }
  }

  &-body-inner {
    height: 100%;
  }

  &-fixed-header > &-content > &-scroll > &-body {
    position: relative;
    background: $component-background;
  }

  &-fixed-header .#{$table-prefix-cls}-body-inner {
    overflow: scroll;
  }

  &-fixed-header .#{$table-prefix-cls}-scroll .#{$table-prefix-cls}-header {
    margin-bottom: -20px;
    padding-bottom: 20px;
    overflow: scroll;
    // Workaround for additional scroll bar on the table header
    // https://github.com/apes-design/apes-design/issues/6515#issuecomment-419634369
    opacity: 0.9999;

    &::-webkit-scrollbar {
      border: 1px solid $border-color-split;
      border-width: 0 0 1px 0;
    }
  }

  &-hide-scrollbar {
    // https://github.com/apes-design/apes-design/issues/4637
    // https://stackoverflow.com/a/54101063
    // https://github.com/react-component/table/pull/333
    scrollbar-color: transparent transparent;
    &::-webkit-scrollbar {
      background-color: transparent;
    }
  }

  // optimize header style of borderd table after hide extra scrollbar
  &-bordered.#{$table-prefix-cls}-fixed-header .#{$table-prefix-cls}-scroll .#{$table-prefix-cls}-header {
    &::-webkit-scrollbar {
      border: 1px solid $border-color-split;
      border-width: 1px 1px 1px 0;
    }
    &.#{$table-prefix-cls}-hide-scrollbar
      .#{$table-prefix-cls}-thead
      > tr:only-child
      > th:last-child {
      border-right-color: transparent;
    }
  }

  &-fixed-left,
  &-fixed-right {
    position: absolute;
    top: 0;
    z-index: $zindex-table-fixed;
    overflow: hidden;
    border-radius: 0;
    transition: box-shadow 0.3s ease;
    table {
      width: auto;
      background: $component-background;
    }
  }

  &-fixed-header .#{$table-prefix-cls}-fixed-left .#{$table-prefix-cls}-body-outer .#{$table-prefix-cls}-fixed,
  &-fixed-header .#{$table-prefix-cls}-fixed-right .#{$table-prefix-cls}-body-outer .#{$table-prefix-cls}-fixed {
    border-radius: 0;
  }

  &-fixed-left {
    left: 0;
    box-shadow: 6px 0 6px -4px $shadow-color;
    .#{$table-prefix-cls}-header {
      overflow-y: hidden;
    }
    // hide scrollbar in left fixed columns
    .#{$table-prefix-cls}-body-inner {
      margin-right: -20px;
      padding-right: 20px;
    }
    .#{$table-prefix-cls}-fixed-header & .#{$table-prefix-cls}-body-inner {
      padding-right: 0;
    }
    &,
    table {
      border-radius: $table-border-radius-base 0 0 0;
    }
    .apes-table-thead > tr > th:last-child {
      border-top-right-radius: 0;
    }
  }

  &-fixed-right {
    right: 0;
    box-shadow: -6px 0 6px -4px $shadow-color;
    &,
    table {
      border-radius: 0 $table-border-radius-base 0 0;
    }
    // hide expand row content in right-fixed Table
    // https://github.com/apes-design/apes-design/issues/1898
    .#{$table-prefix-cls}-expanded-row {
      color: transparent;
      pointer-events: none;
    }
    .apes-table-thead > tr > th:first-child {
      border-top-left-radius: 0;
    }
  }

  .#{$table-prefix-cls}.#{$table-prefix-cls}-scroll-position-left .#{$table-prefix-cls}-fixed-left {
    box-shadow: none;
  }

  .#{$table-prefix-cls}.#{$table-prefix-cls}-scroll-position-right .#{$table-prefix-cls}-fixed-right {
    box-shadow: none;
  }

  // ========================== Row Selection ==========================
  colgroup {
    > col.#{$table-prefix-cls}-selection-col {
      width: $table-selection-column-width;
    }
  }

  &-thead > tr > th.#{$table-prefix-cls}-selection-column-custom {
    .#{$table-prefix-cls}-selection {
      margin-right: -15px;
    }
  }

  &-thead > tr > th.#{$table-prefix-cls}-selection-column,
  &-tbody > tr > td.#{$table-prefix-cls}-selection-column {
    text-align: center;

    .#{$style-prefix}-radio-wrapper {
      margin-right: 0;
    }
  }

  &-row[class*='#{$table-prefix-cls}-row-level-0'] .#{$table-prefix-cls}-selection-column > span {
    display: inline-block;
  }
}

/**
* Another fix of Firefox:
*/
@supports (-moz-appearance: meterbar) {
  // https://github.com/apes-design/apes-design/issues/12628
  .#{$table-prefix-cls}-thead > tr > th.#{$table-prefix-cls}-column-has-actions {
    background-clip: padding-box;
  }
}

@import './size';
